package org.medicalinstrument.action;

import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.medicalinstrument.bean.Customer;
import org.medicalinstrument.bean.Product;
import org.medicalinstrument.bean.ProductVo;
import org.medicalinstrument.bean.RentCart;
import org.medicalinstrument.service.RentCartService;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


/**
 * @Author: kongHuan
 * @Date: 2019/3/14 15:29
 * @Description:
 */
public class rentCartAction extends ActionSupport {
    private String productQR;//主关键字
    private String productType;
    private String productName;
    private String productColor;
    private String productFactory;
    private String productDate;
    private String productPhoto;
    private Integer saleableInformation;
    private Integer productNumber;
    private Float salePrice;
    private Float rentPrice;
    private String isBroken;
    private String brokenDate;
    private Float rentMoney;
    private String introduction;

    private String custName;
    private String custPhone;
    private String password;
    private String accountNo;//主关键字
    private String consigeeAddr;
    private String sex;
    private Integer age;
    private String relateToUser;

    private Integer rentDays;
    private Float price;
    private String proStr;
    private String cartStr;




    public String getProStr() {
        return proStr;
    }

    public void setProStr(String proStr) {
        this.proStr = proStr;
    }

    public String getCartStr() {
        return cartStr;
    }

    public void setCartStr(String cartStr) {
        this.cartStr = cartStr;
    }

    private String rentTime;

    private String returnString;

    private String customer;
    private String product;


    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public String getReturnString() {
        return returnString;
    }

    public void setReturnString(String returnString) {
        this.returnString = returnString;
    }

    public String getCustomer() {
        return customer;
    }

    public void setCustomer(String customer) {
        this.customer = customer;
    }

    public String getProductQR() {
        return productQR;
    }

    public void setProductQR(String productQR) {
        this.productQR = productQR;
    }

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getProductColor() {
        return productColor;
    }

    public void setProductColor(String productColor) {
        this.productColor = productColor;
    }

    public String getProductFactory() {
        return productFactory;
    }

    public void setProductFactory(String productFactory) {
        this.productFactory = productFactory;
    }

    public String getProductDate() {
        return productDate;
    }

    public void setProductDate(String productDate) {
        this.productDate = productDate;
    }

    public String getProductPhoto() {
        return productPhoto;
    }

    public void setProductPhoto(String productPhoto) {
        this.productPhoto = productPhoto;
    }

    public Integer getSaleableInformation() {
        return saleableInformation;
    }

    public void setSaleableInformation(Integer saleableInformation) {
        this.saleableInformation = saleableInformation;
    }

    public Integer getProductNumber() {
        return productNumber;
    }

    public void setProductNumber(Integer productNumber) {
        this.productNumber = productNumber;
    }

    public Float getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(Float salePrice) {
        this.salePrice = salePrice;
    }

    public Float getRentPrice() {
        return rentPrice;
    }

    public void setRentPrice(Float rentPrice) {
        this.rentPrice = rentPrice;
    }

    public String getIsBroken() {
        return isBroken;
    }

    public void setIsBroken(String isBroken) {
        this.isBroken = isBroken;
    }

    public String getBrokenDate() {
        return brokenDate;
    }

    public void setBrokenDate(String brokenDate) {
        this.brokenDate = brokenDate;
    }

    public Float getRentMoney() {
        return rentMoney;
    }

    public void setRentMoney(Float rentMoney) {
        this.rentMoney = rentMoney;
    }

    public String getIntroduction() {
        return introduction;
    }

    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    public String getCustName() {
        return custName;
    }

    public void setCustName(String custName) {
        this.custName = custName;
    }

    public String getCustPhone() {
        return custPhone;
    }

    public void setCustPhone(String custPhone) {
        this.custPhone = custPhone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAccountNo() {
        return accountNo;
    }

    public void setAccountNo(String accountNo) {
        this.accountNo = accountNo;
    }

    public String getConsigeeAddr() {
        return consigeeAddr;
    }

    public void setConsigeeAddr(String consigeeAddr) {
        this.consigeeAddr = consigeeAddr;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getRelateToUser() {
        return relateToUser;
    }

    public void setRelateToUser(String relateToUser) {
        this.relateToUser = relateToUser;
    }

    public Integer getRentDays() {
        return rentDays;
    }

    public void setRentDays(Integer rentDays) {
        this.rentDays = rentDays;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public String getRentTime() {
        return rentTime;
    }

    public void setRentTime(String rentTime) {
        this.rentTime = rentTime;
    }

    RentCartService service = new RentCartService();

    /**
     * @Author: kongHuan
     * @Date: 2019/3/14 19:22
     * @Description:添加商品到租物车
     */
    public String addRentCart(){
        Customer cust = (Customer) JSONObject.toBean(JSONObject.fromObject(customer),Customer.class);
        Product pro = (Product) JSONObject.toBean(JSONObject.fromObject(product),Product.class);
        RentCart cart = new RentCart();
        //封装租物车对象
        cart.setAccountNo(cust.getAccountNo());
        cart.setCustPhone(cust.getCustPhone());
        cart.setPrice(pro.getRentPrice());
        cart.setProductQR(pro.getProductQR());
        cart.setRentDays(rentDays);

        cart.setRentTime(rentTime);

        returnString = service.addAll(cart);
        //System.out.println(returnString);
        return SUCCESS;
    }

    /**
     * @Author: kongHuan
     * @Date: 2019/3/22 9:30
     * @Description:删除租物车选中的商品
     */
    public String deleteItem(){
        List<ProductVo> products;
        products = (List<ProductVo>) JSONArray.toCollection(JSONArray.fromObject(proStr),ProductVo.class);
        System.out.println(accountNo+"-----"+proStr);
        System.out.println(products);
        returnString = service.deleteItem(accountNo,products);
        return SUCCESS;
    }

    /**
     * @Author: kongHuan
     * @Date: 2019/3/15 8:51
     * @Description:通过客户获取租物车信息
     */

    public String showRentCart(){
       // System.out.println(accountNo);
        returnString = service.getByAccountNo(accountNo);
        //System.out.println(returnString);
        return SUCCESS;
    }

    /**
     * @Author: kongHuan
     * @Date: 2019/3/24 18:31
     * @Description:通过主键（账户名，商品二维码）获取租物车信息
     */
    public String selectItem(){
        returnString = service.getByPrimaryKey(accountNo,productQR);
        System.out.println("action----" + returnString);
        return SUCCESS;
    }

    /**
     * @Author: kongHuan
     * @Date: 2019/3/25 8:28
     * @Description:修改租物车记录
     */
    public String update(){

        RentCart cart = (RentCart) JSONObject.toBean(JSONObject.fromObject(cartStr), RentCart.class);
        returnString = service.updateItem(cart);
        System.out.println(returnString);
        return SUCCESS;
    }
}
